package com.foreknow.demo5;

public class ArrayDemo1 {
    public static void main(String[] args) {
        //创建一个数组容器
        int[] array = new int[5];
        //向数组中添加元素
        array[0] = 1;
        array[1] = 2;
        array[2] = 3;
        array[3] = 4;
        array[4] = 5;
        //如何根据下标获取到某个元素
        System.out.println(array[4]);
        //如何获取到数组中的每一个元素(遍历数组) array.length表示数组的长度
        System.out.println("----------------------------------------------");
        for (int i = 0;i < array.length;i++) {
            int a = array[i];
            System.out.println(a);
        }

        String[] array1 = new String[3];
        array1[0] = "fender";
        array1[1] = "gibson";
        array1[2] = "yamaha";

        String name = array1[1];
        System.out.println(name);

        for (int i = 0;i<array1.length;i++) {
            System.out.println(array1[i]);
        }



    }
}
